<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>upload模块快速使用</title>
  <link rel="stylesheet" href="/layui/css/layui.css" media="all">
</head>
<body>

<div>
  <div>
    <button type="button" class="layui-btn" id="test1">
      <i class="layui-icon">&#xe67c;</i>上传图片
    </button>
  </div>
  <div>
    <img id="img1">
  </div>
</div>


<script src="/layui/layui.js"></script>
<script>
  layui.use('upload', function(){
    var upload = layui.upload,
            $=layui.$;

    //执行实例
    var uploadInst = upload.render({
      elem: '#test1' //绑定元素
      ,url: '/api/file/fileupload.do' //上传接口
      ,done: function(res){
        //上传完毕回调
        if(res.code==0){
          //上传成功
          $("#img1")[0].src=res.data;
        }else {
          layer.msg("亲，上传失败！");
        }
      }
      ,error: function(){
        //请求异常回调
      }
    });
  });
</script>
</body>
</html>